﻿namespace NTLib.WPF.Interactions.Actioners
{
    using NTLib.WPF.Interactions;
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;

    /// <summary>
    /// 
    /// </summary>
    /// <seealso cref="NTLib.WPF.Interactions.BaseActionner" />
    public class EventInvokeCommandActionner : BaseActioner
    {
        #region Property

        public ICommand Command
        {
            get { return (ICommand)GetValue(CommandProperty); }
            set { SetValue(CommandProperty, value); }
        }

        // Using a DependencyProperty as the backing store for Command.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandProperty =
            DependencyProperty.Register("Command", typeof(ICommand), typeof(EventInvokeCommandActionner), new PropertyMetadata(null));

        public object CommandParameter
        {
            get { return (object)GetValue(CommandParameterProperty); }
            set { SetValue(CommandParameterProperty, value); }
        }

        // Using a DependencyProperty as the backing store for CommandParameter.  This enables animation, styling, binding, etc...
        public static readonly DependencyProperty CommandParameterProperty =
            DependencyProperty.Register("CommandParameter", typeof(object), typeof(EventInvokeCommandActionner), new PropertyMetadata(null));

        #endregion

        #region Methods

        /// <summary>
        /// Invokes the specified parameters.
        /// </summary>
        /// <param name="parameters">The parameters.</param>
        public override void Invoke(object parameters)
        {
            if (CommandParameter != null)
                parameters = CommandParameter;
            if (Command != null && Command.CanExecute(parameters))
                Command.Execute(parameters);
        }

        #endregion
    }
}
